package com.heaboy.emaidemo1.config;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.Map;

@Configuration
@ConfigurationProperties(prefix = "mail")
public class MailProperties {
    private String defaultType;
    // 必须初始化 HashMap，确保 Spring 能直接注入
    private Map<String, MailConfig> configs = new HashMap<>();

    public String getDefaultType() {
        return defaultType;
    }

    public void setDefaultType(String defaultType) {
        this.defaultType = defaultType;
    }

    public Map<String, MailConfig> getConfigs() {
        return configs;
    }

    public void setConfigs(Map<String, MailConfig> configs) {
        this.configs = configs; // 直接赋值，无自定义逻辑
    }


    public static class MailConfig {
        // 初始化嵌套对象
        private Sender sender = new Sender();
        private Smtp smtp = new Smtp();
        private Default defaults = new Default();


        public void setSender(Sender sender) {
            this.sender = sender;
        }

        public void setSmtp(Smtp smtp) {
            this.smtp = smtp;
        }

        public void setDefaults(Default defaults) {
            this.defaults = defaults;
        }

        // 原有 getter 保留
        public Sender getSender() {
            return sender;
        }

        public Smtp getSmtp() {
            return smtp;
        }

        public Default getDefaults() {
            return defaults;
        }

        public static class Sender {
            private String username;
            private String password;
            private String name;

            public String getUsername() { return username; }
            public void setUsername(String username) { this.username = username; }
            public String getPassword() { return password; }
            public void setPassword(String password) { this.password = password; }
            public String getName() { return name; }
            public void setName(String name) { this.name = name; }
        }

        public static class Smtp {
            private String host;
            private int port;
            private boolean auth;
            private boolean sslEnable;
            private String socketFactoryClass;
            private int socketFactoryPort;

            public String getHost() { return host; }
            public void setHost(String host) { this.host = host; }
            public int getPort() { return port; }
            public void setPort(int port) { this.port = port; }
            public boolean isAuth() { return auth; }
            public void setAuth(boolean auth) { this.auth = auth; }
            public boolean isSslEnable() { return sslEnable; }
            public void setSslEnable(boolean sslEnable) { this.sslEnable = sslEnable; }
            public String getSocketFactoryClass() { return socketFactoryClass; }
            public void setSocketFactoryClass(String socketFactoryClass) { this.socketFactoryClass = socketFactoryClass; }
            public int getSocketFactoryPort() { return socketFactoryPort; }
            public void setSocketFactoryPort(int socketFactoryPort) { this.socketFactoryPort = socketFactoryPort; }
        }

        public static class Default {
            private String title;
            private String content;

            public String getTitle() { return title; }
            public void setTitle(String title) { this.title = title; }
            public String getContent() { return content; }
            public void setContent(String content) { this.content = content; }
        }
    }
}